//
//  UpdateNoticeView.m
//  gungunchou
//
//  Created by LJJ on 2017/11/15.
//  Copyright © 2017年 xskj. All rights reserved.
//

#import "UpdateNoticeView.h"

@interface UpdateNoticeView ()

@property (weak, nonatomic) IBOutlet UIImageView *backImgv;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *btn1Leading;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *btn2Trailing;

@end

@implementation UpdateNoticeView

- (void)awakeFromNib
{
    [super awakeFromNib];
    if (SCREEN_WIDTH == 320) {
        self.btn1Leading.constant = 16;
        self.btn2Trailing.constant = 16;
    }
    else if (SCREEN_WIDTH == 375) {
        self.btn1Leading.constant = 18;
        self.btn2Trailing.constant = 18;
    }
    else if (SCREEN_WIDTH == 414) {
        self.btn1Leading.constant = 20;
        self.btn2Trailing.constant = 20;
    }
}

- (IBAction)updateClick:(id)sender {
    //进入appstore更新
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.updateUrl]];//服务器提供appstore更新地址
    [self exitApp];
}

- (IBAction)cancelClick:(id)sender {
    NSString *cancelTitle = self.cancelBtn.titleLabel.text;
    if ([cancelTitle isEqualToString:@"取消"]) {
        [NotificationCenter postNotificationName:CloseUpdateNotice object:nil];
    }
    else if ([cancelTitle isEqualToString:@"退出"]) {
        [self exitApp];
    }
}

//退出应用
- (void)exitApp {
    UIWindow *window = self.window;
    [UIView animateWithDuration:0.5f animations:^{
        window.alpha = 0;
        window.frame = CGRectMake(0,SCREEN_HEIGHT/2-100, SCREEN_WIDTH, 0);
    } completion:^(BOOL finished) {
        exit(0);
    }];
}
@end
